package com.gxa.autoparts.portal.controller;

import com.gxa.autoparts.core.common.JsonResult;
import com.gxa.autoparts.portal.service.SecondKillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;
import java.util.Set;

@RestController
@Api(tags = "商品检索器模块")
@RequestMapping("/secondKill")
public class SecondKillController {
    @Autowired
    SecondKillService secondKillService=null;
    @PostMapping("/goodsKill")
    @ApiOperation("商品秒杀")
    public Map secondKill(@RequestParam("goodsId") Long goodsId) throws ParseException {

        Boolean secondKillTime = secondKillService.isSecondKillTime(1L);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(secondKillTime);
        return jsonResult.getDataMap();
    }

    @PostMapping("/set")
    @ApiOperation("redis设置时间")
    public Map secondKill() throws ParseException {
        secondKillService.set();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }
}
